<?php
    class Admin_con extends CI_Controller{
        function __construct() {
            parent::__construct();
        }
        function index(){
            $this->login();
        }
        function login(){
            if ($this->session->userdata('login')==TRUE) {
                redirect(base_url().'admin/admin_con/banner');
            }
            $this->load->view("admin/admin_header_view");
            $this->load->view("admin/login_view");
            $this->load->view("admin/admin_footer_view");
            
        }
        function proses_login(){
            if(!isset($_POST['username'])||!isset($_POST['password'])) {
                redirect(base_url().'admin/admin_con/login');
            }
            $usr = $this->input->post('username');
            $pwd = md5($this->input->post('password'));
            $query_peserta = $this->db->query('select * from user natural join role WHERE USERNAME="'.$usr.'" and PASSWORD="'.$pwd.'" and ID_ROLE=10');
            
            if(count($query_peserta->result_array())!=1) {
                //error jika ada kesalahan login, jenis error 1
                redirect(base_url().'admin/admin_con/login');
            }else {
                $data_peserta=$query_peserta->row_array();
                $data_session = array(
                        'id'=>$data_peserta['ID'],
                        'nama'=>$data_peserta['NAMA'],
                        'login'=>true,
                );
                $this->session->set_userdata($data_session);

                redirect(base_url().'admin/admin_con/banner');
            }            
        }
        function banner(){
            if ($this->session->userdata('login')!=TRUE) {
                redirect(base_url().'admin/admin_con/login');
            }
            $gallery_path = realpath(APPPATH . '../images/gallery');
            $gallery_path_url = base_url().'images/gallery/';
            $files = scandir($gallery_path);
            $files = array_diff($files, array('.','..','thumbs'));

            $banner = $this->db->query('SELECT * FROM featured_images')->result_array();
            $images = array();

            foreach ($files as $file) {
                if((strlen($file)>4)){
                    if($this->isJpg($file)||$this->isGif($file)||$this->isPng($file)){
                        $ada = false;
                        if(count($banner)>0){
                            for($i=0;$i<count($banner);$i++){
                                if($banner[$i]['LOKASI_GAMBAR']==$gallery_path_url . $file){
                                    $ada = true;
                                }
                            }
                        }
                        if($ada){
                            $images[] = array(
                                'url' => $gallery_path_url . $file,
                                'thumb_url'=>$gallery_path_url .'thumbs/' . $file,
                                'checked'=>true
                            );
                        }else{
                            $images[] = array(
                                'url' => $gallery_path_url . $file,
                                'thumb_url'=>$gallery_path_url .'thumbs/' . $file,
                                'checked'=>false
                            );
                        }
                    }
                }
            }
            $display['images'] = $images;
            $this->load->view("admin/admin_header_view");
            $this->load->view("admin/banner_view",$display);
            $this->load->view("admin/admin_footer_view");
        }
        function update_banner(){
            $display = Array();
            $pilihan = $this->input->post('image');
            $counter = 1;
            $delete = $this->db->query('DELETE FROM featured_images');
            if(!empty($pilihan)){
                foreach ($pilihan as $pilih){
                    //echo $pilih;
                    $query = $this->db->get_where('featured_images', array(
                                'ID_GAMBAR' => ($counter)
                            ));
                    if ($query->num_rows() <= 0) {
                        $data = array(
                                'ID_GAMBAR' => ($counter),
                                'LOKASI_GAMBAR' => $pilih,
                        );
                        $this->db->insert('featured_images', $data);                

                    }else{
                        $data = array(
                                'LOKASI_GAMBAR' => $pilih

                            );
                        $where = array('ID_GAMBAR' => ($counter));
                        $this->db->where($where);
                        $this->db->update('featured_images', $data);                
                    }
                    $counter+=1;
                }
            }
            redirect(base_url()."admin/admin_con/banner");
        }
        function do_upload()
	{
            $gallery_path = realpath(APPPATH . '../images/gallery');
            $config = array(
                'allowed_types'=>'jpg|jpeg|gif|png',
                'upload_path' => $gallery_path,
                'max_size' => 20000,
                'max_width' =>782,
                'max_height' =>324,
                'min_width' =>782,
                'min_height' =>324
            );

            $this->load->library('upload',$config);
//            $this->upload->do_upload();
//            $image_data = $this->upload->data();
//            //echo $image_data['full_path'];
//            unset($config);
//            $config = array(
//            'source_image'=> $image_data['full_path'],
//            'new_image'=>$gallery_path . '/thumbs',
//            'upload_path' => $gallery_path,
//            'maintain_ration'=>true,
//            'width'=>160,
//            'height'=>120
//            );
//            $this->load->library('image_lib', $config);
//            $this->image_lib->resize();
//            
//
//		$config['file_name'] = 'gal';
//		$config['upload_path'] = './images/gallery/';
//		$config['allowed_types'] = 'gif|jpg|png';
//		$config['max_size']	= '100';
//		$config['max_width']  = '1024';
//		$config['max_height']  = '768';
//                echo $config['upload_path'].$config['file_name'];
//		$this->load->library('upload', $config);

		if ( ! $this->upload->do_upload())
		{
                    redirect(base_url().'admin/admin_con/image_management/9999');
		}
		else
		{
                    $image_data = $this->upload->data();
                    $config = array(
                    'source_image'=> $image_data['full_path'],
                    'new_image'=>$gallery_path . '/thumbs',
                    'upload_path' => $gallery_path,
                    'maintain_ration'=>true,
                    'width'=>160,
                    'height'=>120
                    );
                    $this->load->library('image_lib', $config);
                    $this->image_lib->resize();
                    //echo "sukses";
			//$data = array('upload_data' => $this->upload->data());

			//$this->load->view('upload_success', $data);
		}
            redirect(base_url().'admin/admin_con/image_management/');
	}
        function product(){
            if ($this->session->userdata('login')!=TRUE) {
                redirect(base_url().'admin/admin_con/login');
            }
            $queryID = $this->db->query('SELECT * FROM pelatihan')->result_array();
            $list_pelatihan['none'] = "none";
            for($i=0;$i<count($queryID);$i++){
                $list_pelatihan[$queryID[$i]['KODE_PELATIHAN']] = $queryID[$i]['KODE_PELATIHAN']." - ".$queryID[$i]['NAMA_PELATIHAN'];
            }
            $pilihan = $this->db->query('SELECT * FROM featured_product')->result_array();
            for($i=0;$i<=(7-count($pilihan));$i++){
                $data = array(
                        'id' => ($i+1+count($pilihan)),
                        'KODE_PELATIHAN' => 'none',
                        'STATUS_NEW' => '0',
                );
                $this->db->insert('featured_product', $data);                
                
            }
            $pilihan = $this->db->query('SELECT * FROM featured_product')->result_array();
            if(count($pilihan)>0){
                $display['pilihan'] = $pilihan;
            }
            $display['product'] = $list_pelatihan;
            $this->load->view("admin/admin_header_view");
            $this->load->view("admin/product_view", $display);
            $this->load->view("admin/admin_footer_view");
            
        }
        function update_product(){
            for ($i=0;$i<=7;$i++){
                $check = false;
                $product[$i]= $this->input->post('product'.($i+1));
                $pilihan = $this->input->post('pilihan'.($i+1));
                for($j=0;$j<$i;$j++){
                    if(($product[$j]==$product[$i]) && ($product[$j]!='none')){
//                        echo "ada yang sama ".$product[$j].' '.$product[$i];
                        $check = true;
                        $product[$i] = 'none';
                        $pilihan  = 0;
                    }else{
                        
                    }
                }
                //if(!$check){
                    $query = $this->db->get_where('featured_product', array(
                                'id' => ($i+1)
                            ));
                    if (empty($pilihan)){
                        $status = 0;
                    }else{
                        $status = 1;
                    }
                    if ($query->num_rows() <= 0) {
                        $data = array(
                                'id' => ($i+1),
                                'KODE_PELATIHAN' => $product[$i],
                                'STATUS_NEW' => $status,
                        );
                        $this->db->insert('featured_product', $data);                

                    }else{
                        $data = array(
                                'KODE_PELATIHAN' => $product[$i],
                                'STATUS_NEW' => $status,

                            );
                        $where = array('id' => ($i+1));
                        $this->db->where($where);
                        $this->db->update('featured_product', $data);                
                    }
//                }

            }
            redirect(base_url().'admin/admin_con/product');
        }
        function news_management(){
            if ($this->session->userdata('login')!=TRUE) {
                redirect(base_url().'admin/admin_con/login');
            }
            $display=Array();
            $news = $this->db->query('SELECT * FROM news')->result_array();
            if(count($news)>0){
				$display['news']=$news;                
            }
            $this->load->view('admin/admin_header_view');
            $this->load->view('admin/news_management_view',$display);
            $this->load->view('admin/admin_footer_view');
            
        }
        function delete_news($id){
            if ($this->session->userdata('login')!=TRUE) {
                redirect(base_url().'admin/admin_con/login');
            }
            $this->db->where('ID_BERITA',($id));
            $this->db->delete('news');
            redirect(base_url().'admin/admin_con/news_management');
        }
        function news(){
            if ($this->session->userdata('login')!=TRUE) {
                redirect(base_url().'admin/admin_con/login');
            }
            $this->load->library('form_validation'); //meload library untuk validasi form
            $this->form_validation->set_rules('judul','Judul','required');
            $this->form_validation->set_rules('isi','Isi','required');
            //$this->form_validation->set_rules('kategori','Kategori','required');
            
            if($this->form_validation->run()==FALSE){
                
                /*Mengisikan pilihan kategori dari tabel daftar kategori*/
                $this->crud->use_table('news');
                $criteria = array('ID_BERITA !=' => 0);
                $query = $this->crud->retrieve($criteria);                
                foreach($query->result() as $row){
                    $isi['id_pilihan'][]=$row->ID_BERITA;
                    $isi['nama_pilihan'][]=$row->JUDUL;
                }
                
                
                /*Menampilkan view dengan data-data yang sudah didefinisikan ($data dan $isi)*/
                /*$data akan memerikan judul halaman dengan nama $title, dipassing ke header_view*/
                /*$isi akan diisikan pilihan kategori hasil queru dari database dan id dari inputan yang sekarang*/
                /*$isi akan dipassing ke news_form*/
                $this->load->library('wysiwyg');
                $data['script']=$this->wysiwyg->loadScript();   //form akan menggunakan textarea WYSIWYG
                $data['title']="Buat berita";
                
                $queryID = $this->db->query('SELECT max(ID_BERITA) id FROM news');   // Mencari id dari inputan ini            
                $row = $queryID->row();
                $id = $row->id+1;
                $isi['id']=$id;
                $this->load->view('admin/admin_header_view',$data);
                $this->load->view('admin/news_view',$isi);
                $this->load->view('admin/admin_footer_view');
            
            }else{
                /*Mengambil data-data dengan method post dari form isi berita*/
                $judul = $this->input->post('judul');
                $isi = $this->input->post('isi');
                $id = $this->input->post('id');
                $tanggal = date('Y-m-d', time());
                $waktu = date('h:m:s', time());

                /*Mengunakan model bernama crud untuk memasukkan data input berita dari user*/
                $this->crud->use_table('news');
                $data_in = array('JUDUL'=>$judul,'ISI'=>$isi,'TGL'=>$tanggal, 'WAKTU'=>$waktu, 'ID_USER'=>$this->session->userdata('id'));
                
                if($this->crud->create($data_in))
                    redirect(base_url().'admin/admin_con/news_management');
            }
            
        }
        function edit_news($id_berita=-1){
            if ($this->session->userdata('login')!=TRUE) {
                redirect(base_url().'admin/admin_con/login');
            }
            $this->load->library('form_validation'); //meload library untuk validasi form
            $this->form_validation->set_rules('judul','Judul','required');
            $this->form_validation->set_rules('isi','Isi','required');
            
            if($this->form_validation->run()==FALSE){
                
                /*Mengisikan pilihan kategori dari tabel daftar kategori*/
                $this->crud->use_table('news');
                $criteria = array('ID_BERITA !=' => 0);
                $query = $this->crud->retrieve($criteria);
                
                foreach($query->result() as $row){
                    $isi['id_pilihan'][]=$row->ID_BERITA;
                    $isi['nama_pilihan'][]=$row->JUDUL;
                }
                
                $this->load->library('wysiwyg');
                $data['script']=$this->wysiwyg->loadScript();   //form akan menggunakan textarea WYSIWYG
                $data['title']="Buat berita";
                
                $queryID = $this->db->query('SELECT max(ID_BERITA) id FROM news');   // Mencari id dari inputan ini            
                $row = $queryID->row();
                $id = $row->id+1;
                $isi['id']=$id;
                $query = $this->db->query('SELECT * FROM news where ID_BERITA='.$id_berita.'')->result_array();
                if (count($query)>0){
                    $isi['news'] = $query[0];
                    $isi['id']=$query[0]['ID_BERITA'];
                }
                $this->load->view('admin/admin_header_view',$data);
                $this->load->view('admin/news_view', $isi);
                $this->load->view('admin/admin_footer_view');
            
            }else{
                
                /*Mengambil data-data dengan method post dari form isi berita*/
                $judul = $this->input->post('judul');
                $isi = $this->input->post('isi');
                $id = $this->input->post('id');
                $jenis = $this->input->post('jenis');
                $file = $_FILES['userfile'];
                $tanggal = date('Y-m-d', time());
                $waktu = date('h:m:s', time());
                $tambah = false;
                if ($id_berita==-1){
                    $tambah = true;
                }else{
                    $query = $this->db->get_where('news', array(
                                'ID_BERITA' => $id_berita
                            ));
                    if ($query->num_rows() <= 0) {
                        $tambah = true;
                    }   
                }
                
                if ($tambah){
                    $this->crud->use_table('news');
                    if(!empty($file['name'])){
                        $gallery_path = realpath(APPPATH . '../images/news');
                        $config = array(
                            'allowed_types'=>'jpg|gif|png',
                            'upload_path' => $gallery_path,
                            'max_size' => 20000
                        );

                        $this->load->library('upload',$config);
                        if($this->upload->do_upload()){
                            $data_in = array('JUDUL'=>$judul,'ISI'=>$isi,'TGL'=>$tanggal, 'GAMBAR'=>base_url().'images/news/'.$this->upload->file_name,'WAKTU'=>$waktu, 'ID_USER'=>$this->session->userdata('id'));
                        }else{
                            $data_in = array('JUDUL'=>$judul,'ISI'=>$isi,'TGL'=>$tanggal,'WAKTU'=>$waktu, 'ID_USER'=>$this->session->userdata('id'));
                        }
                    }else{
                        $data_in = array('JUDUL'=>$judul,'ISI'=>$isi,'TGL'=>$tanggal,'WAKTU'=>$waktu, 'ID_USER'=>$this->session->userdata('id'));
                    }
                    if($this->crud->create($data_in))
                    redirect(base_url().'admin/admin_con/news_management');                    
                }else{
                    if(!empty($file['name'])){
                        $gallery_path = realpath(APPPATH . '../images/news');
                        $config = array(
                            'allowed_types'=>'jpg|gif|png',
                            'upload_path' => $gallery_path,
                            'max_size' => 20000,
                            'overwrite'=>true
                        );

                        $this->load->library('upload',$config);
                        if($this->upload->do_upload()){
                            $data = array('JUDUL'=>$judul,'ISI'=>$isi,'JENIS'=>$jenis, 'GAMBAR'=>base_url().'images/news/'.$this->upload->file_name,'WAKTU'=>$waktu, 'ID_USER'=>$this->session->userdata('id'));   
                        }else{
                            $data = array('JUDUL'=>$judul,'ISI'=>$isi,'JENIS'=>$jenis, 'ID_USER'=>$this->session->userdata('id'));
                        }
                        $where = array('ID_BERITA' =>$id_berita);
                        $this->db->where($where);
                        $this->db->update('news', $data);                    
                        redirect(base_url().'admin/admin_con/news_management'); 
                    }else{
                        $data = array('JUDUL'=>$judul,'ISI'=>$isi,'JENIS'=>$jenis, 'ID_USER'=>$this->session->userdata('id'));
                        $where = array('ID_BERITA' =>$id_berita);
                        $this->db->where($where);
                        $this->db->update('news', $data);                    
                        redirect(base_url().'admin/admin_con/news_management');
					}
                }
                
            }
        }
        
        
        function image_management($error=0){
            if ($this->session->userdata('login')!=TRUE) {
                redirect(base_url().'admin/admin_con/login');
            }
            if($error!=0){
                $display['warning'] = "Gagal melakukan upload file, pastikan file berukuran 782x324 pixel dan berformat jpg|gif|png";
            }
            $gallery_path = realpath(APPPATH . '../images/gallery');
            $gallery_path_url = base_url().'images/gallery/';
            $files = scandir($gallery_path);
            $files = array_diff($files, array('.','..','thumbs'));

            $images = array();

            foreach ($files as $file) {
                if((strlen($file)>4)){
                    if($this->isJpg($file)||$this->isGif($file)||$this->isPng($file)){
                        //echo $file."<br>";
                        $images[] = array(
                            'url' => $gallery_path_url . $file,
                            'thumb_url'=>$gallery_path_url .'thumbs/' . $file,
                        );
                    }
                }
            }
            
        
            $display['images'] = $images;
            $this->load->view("admin/admin_header_view");
            $this->load->view("admin/image_management_view",$display);
            $this->load->view("admin/admin_footer_view");            
        }
        function isPng($file){
            if ((strtolower($file[strlen($file)-1]=='g')) && (strtolower($file[strlen($file)-2]=='n')) && (strtolower($file[strlen($file)-3]=='p'))&&($file[strlen($file)-4]=='.')){
                return true;
            }
            else{
                return false;
            }
        }
        function isGif($file){
            if ((strtolower($file[strlen($file)-1]=='f')) && (strtolower($file[strlen($file)-2]=='i')) && (strtolower($file[strlen($file)-3]=='g'))&&($file[strlen($file)-4]=='.')){
                return true;
            }
            else{
                return false;
            }
        }
        function isJpg($file){
            if ((strtolower($file[strlen($file)-1]=="g")) && (strtolower($file[strlen($file)-2]=="p")) && (strtolower($file[strlen($file)-3]=="j"))&&($file[strlen($file)-4]==".")){
                return true;
            }
            else{
                return false;
            }
        }
        function delete_image($index){
            $gallery_path = realpath(APPPATH . '../images/gallery');
            $gallery_path_url = base_url().'images/gallery/';
            $files = scandir($gallery_path);
            $files = array_diff($files, array('.','..','thumbs'));

            $images = array();

            foreach ($files as $file) {
                if((strlen($file)>4)){
                    if($this->isJpg($file)||$this->isGif($file)||$this->isPng($file)){
                $images[] = array(
                    'url' => $gallery_path_url . $file,
                    'thumb_url'=>$gallery_path_url .'thumbs/' . $file,
                    'filename'=>$file
                );}
                }
            }
            //echo 'images/gallery/'.$images[$index-1]['filename'];
            unlink('images/gallery/'.$images[$index-1]['filename']);  
            unlink('images/gallery/thumbs/'.$images[$index-1]['filename']);
            redirect(base_url().'admin/admin_con/image_management');
        }
        function yahoo(){
            if ($this->session->userdata('login')!=TRUE) {
                redirect(base_url().'admin/admin_con/login');
            }
            $display = Array();
            $ym = $this->db->query('SELECT * FROM akun_ym')->result_array();   // 
            $display['yahoo'] = $ym;
            $this->load->view("admin/admin_header_view");
            $this->load->view("admin/yahoo_view",$display);
            $this->load->view("admin/admin_footer_view");            
            
        }
        function update_yahoo(){
            if ($this->session->userdata('login')!=TRUE) {
                redirect(base_url().'admin/admin_con/login');
            }
            $display = Array();
            $ym = $this->db->query('SELECT * FROM akun_ym')->result_array();   // 
            if(count($ym)<3){
                $counter=count($ym);
                while($counter<3){
                    $counter+=1;
                    $this->crud->use_table('akun_ym');
                    $data_in = array('ID'=>$counter,'USERNAME_YM'=>"");

                    if($this->crud->create($data_in)){
                    }else{
                    }
                }
            }
            for($i=1;$i<=3;$i++){         
                $akun = $this->input->post('yahoo'.$i);
                $data = array(
                        'USERNAME_YM' => $akun
                    );
                $where = array('ID' => ($i));
                $this->db->where($where);
                $this->db->update('akun_ym', $data);                
            }
            redirect(base_url().'admin/admin_con/yahoo');
        }
        function testimonial($kode_pelatihan){
            if ($this->session->userdata('login')!=TRUE) {
                redirect(base_url().'admin/admin_con/login');
            }
            $display=Array();
            $jawaban = $this->db->query('SELECT * FROM jawaban inner join user on user.ID=jawaban.ID_USER where KODE_PELATIHAN="'.$kode_pelatihan.'" and ID_PERTANYAAN=19 ')->result_array();
            if(count($jawaban)>0){
                for($i=0;$i<count($jawaban);$i++){
                    $jawaban[$i]['CEKLIS'] = 0;
                }
                $testimonial = $this->db->query('SELECT * FROM testimonial')->result_array();   // 
                if(count($testimonial)>0){
                    for($i=0;$i<count($testimonial);$i++){
                        $id = $this->findIDUser($jawaban, $testimonial[$i]['ID_USER']);
                        if($id!=-1){     
                            $jawaban[$id]['CEKLIS'] = 1;
                        }
                    }
                }
                $display['testimonial'] = $jawaban;
            }
            $display['kode_pelatihan'] = $kode_pelatihan;
            
            $this->load->view("admin/admin_header_view");
            $this->load->view("admin/testimonial_view",$display);
            $this->load->view("admin/admin_footer_view");            
        }
        
        function edit_testimoni($param){
            $data = explode('-', $param);
            
            $where = array(
                'ID_PERTANYAAN'=>$data[0],
                'ID_USER'=>$data[1],
                'KODE_PELATIHAN'=>$data[2],
                'ANGKATAN'=>$data[3],
                'NOMOR_SESI'=>$data[4]
            );
            
            $display['result']=$this->db->get_where('jawaban',$where)->row_array();
            
            
            $this->load->view("admin/admin_header_view");
            $this->load->view("admin/edit_testimonial_view",$display);
            $this->load->view("admin/admin_footer_view");
        }
        
        function simpan_edit_testimoni(){
            $jawaban = $_POST['JAWABAN'];
            unset($_POST['JAWABAN']);
            $this->db->where($_POST);
            $this->db->update('jawaban',array('JAWABAN'=>$jawaban));
            redirect(base_url().'admin/admin_con/testimonial/'.$_POST['KODE_PELATIHAN']);
        }
        
        function category_testimonial(){
            if ($this->session->userdata('login')!=TRUE) {
                redirect(base_url().'admin/admin_con/login');
            }
            $display=Array();
            $pelatihan = $this->db->query('SELECT distinct pelatihan.KODE_PELATIHAN, pelatihan.NAMA_PELATIHAN FROM pelatihan inner join jawaban on jawaban.KODE_PELATIHAN=pelatihan.KODE_PELATIHAN where jawaban.ID_PERTANYAAN=19')->result_array();   // 
            if(count($pelatihan)>0){
                $display['pelatihan'] = $pelatihan;
            }
            $this->load->view("admin/admin_header_view");
            $this->load->view("admin/testimonial_category_view",$display);
            $this->load->view("admin/admin_footer_view");                        
        }
        function findIDUser($jawaban,$id){
            $found=false;
            $counter=0;
            while((!$found)&&($counter<count($jawaban))){
                if($jawaban[$counter]['ID_USER']==$id){
                    $found = true;
                }else{
                $counter+=1;
                }
            }
            if($found) return $counter; 
            else return -1;
        }
        function update_testimonial(){
            if ($this->session->userdata('login')!=TRUE) {
                redirect(base_url().'admin/admin_con/login');
            }
            $display=Array();
            $kode_pelatihan=$this->input->post('kode_pelatihan');
            $testimonial = $this->db->query('SELECT * FROM testimonial where KODE_PELATIHAN="'.$kode_pelatihan.'"')->result_array();   // 
            for($i=0;$i<count($testimonial);$i++){
                $this->db->where('ID',($testimonial[$i]['ID']));
                $this->db->delete('testimonial');                
            }
            $testimonial = $this->db->query('SELECT * FROM testimonial')->result_array();   // 
            $input_testi=$this->input->post('testimonial');
//            echo count($input_testi);
            if(!empty($input_testi)){
                $queryID = $this->db->query('SELECT max(ID) id FROM testimonial');   // Mencari id dari inputan ini            
                $row = $queryID->row();
                $i = $row->id+1;
                foreach ($input_testi as $testi){
                    $id_user=$this->input->post('user'.$testi);
                    $kode_pelatihan=$this->input->post('kode_pelatihan');
                    $angkatan=$this->input->post('angkatan'.$testi);
                    $nomor_sesi=$this->input->post('sesi'.$testi);
                    $data = array(
                            'KODE_PELATIHAN' => ($kode_pelatihan),
                            'ANGKATAN' => ($angkatan),
                            'NOMOR_SESI' => ($nomor_sesi),
                            'ID_USER' => ($id_user),
                            'ID' => ($i+1)
                        );
                    $i+=1;
                    $this->db->insert('testimonial', $data);                
                }
            }
            redirect(base_url().'admin/admin_con/testimonial/'.$kode_pelatihan);
        }
    }
?>